package com.zj.core.ui

import android.content.Context
import android.graphics.Color
import android.support.constraint.ConstraintLayout
import android.support.v7.widget.RecyclerView
import android.view.Gravity
import android.view.View
import android.view.ViewManager
import android.widget.Button
import android.widget.ImageView
import android.widget.LinearLayout
import com.zj.core.R
import org.jetbrains.anko.*
import org.jetbrains.anko.constraint.layout.constraintLayout
import org.jetbrains.anko.constraint.layout.guideline
import org.jetbrains.anko.custom.ankoView

class RecordActivityUi(groupView: LinearLayout): AnkoComponent<Context> {
    private var view:LinearLayout=groupView

    lateinit var record_scroll:RecyclerView
    lateinit var recordCleanView: Button
    lateinit var recordConnectDevice:Button
    lateinit var recordCommitBu:Button
    lateinit var voiceImgView:ImageView

    override fun createView(ui: AnkoContext<Context>): View=with(view){
        constraintLayout {
            lparams(width= matchParent,height= matchParent)
            backgroundColor=context.resources.getColor(R.color.colorsFrenchWhite)

            guideline{
                id= R.id.guideline_h_80
            }.lparams(width= matchParent,height= wrapContent){
                orientation= ConstraintLayout.LayoutParams.HORIZONTAL
                guidePercent=0.87F
            }

            record_scroll=recyclerview{
                id=R.id.record_scroll
                backgroundColor=Color.WHITE
                //fitsSystemWindows=true     //布局上移
            }.lparams(width= matchParent,height = 0){
                topToTop=ConstraintLayout.LayoutParams.PARENT_ID
                bottomToTop=R.id.lly_buttom
                leftToLeft=ConstraintLayout.LayoutParams.PARENT_ID
                rightToRight=ConstraintLayout.LayoutParams.PARENT_ID
            }

            linearLayout {
                id=R.id.lly_buttom
                orientation=LinearLayout.HORIZONTAL
                gravity=Gravity.CENTER

                recordCleanView=button{
                    text="清除"
                    id=R.id.record_clean_view_bu
                }.lparams(width=0,height= wrapContent){
                    weight=1F
                }

                recordConnectDevice=button{
                    text="设备"
                    visibility=View.GONE
                    id=R.id.record_connect_device
                }.lparams(width=0,height=wrapContent){
                    weight=1F
                }

                recordCommitBu=button{
                    text="提交"
                    id=R.id.record_save_view_bu
                }.lparams(width=0,height=wrapContent){
                    weight=1F
                }
            }.lparams(width=0,height = 0){
                topToBottom=R.id.guideline_h_80
                bottomToBottom=ConstraintLayout.LayoutParams.PARENT_ID
                leftToLeft=ConstraintLayout.LayoutParams.PARENT_ID
                rightToRight=ConstraintLayout.LayoutParams.PARENT_ID
            }

            voiceImgView=imageView{
                id=R.id.voice_img_view
                visibility=View.GONE
                image=context.resources.getDrawable(R.mipmap.ease_record_animate_01)
                background=context.resources.getDrawable(R.drawable.border_line_voice_view)
                padding=15
            }.lparams(width=150,height = 150){
                topToTop=ConstraintLayout.LayoutParams.PARENT_ID
                bottomToBottom=ConstraintLayout.LayoutParams.PARENT_ID
                leftToLeft=ConstraintLayout.LayoutParams.PARENT_ID
                rightToRight=ConstraintLayout.LayoutParams.PARENT_ID
            }
        }
    }

    inline fun ViewManager.recyclerview(theme: Int = 0, init:RecyclerView.() -> Unit) :RecyclerView {
        return ankoView({ RecyclerView(it) }, theme, init)
    }
}